package com.yanqu.road.entity.kuang.config;

import com.yanqu.road.entity.config.system.PropertyWeightItem;
import com.yanqu.road.entity.kuang.KuangRankRewardConfig;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 后台配置信息
 */
public class KuangSystemConfig {

    /**
     * 个人战绩榜排行榜奖励配置
     * 开服天数区间索引，奖励list
     */
    private Map<Integer, List<KuangRankRewardConfig>> personRankRewardConfigMap = new ConcurrentHashMap<>();

    /**
     * 阵营积分榜排行榜奖励配置
     * 开服天数区间索引，奖励list
     */
    private Map<Integer, List<KuangRankRewardConfig>> groupRankRewardConfigMap = new ConcurrentHashMap<>();

    /**
     * 矿山-宝库普通奖励
     */
    private Map<Integer, List<PropertyWeightItem>> lotteryGeneraRewardMap = new ConcurrentHashMap<>();

    /**
     * 矿山-宝库珍稀大奖
     */
    private Map<Integer, List<PropertyWeightItem>> lotterySpecialRewardMap = new ConcurrentHashMap<>();

    /**
     * 矿山-宝库抽奖消耗
     */
    private Property lotteryCost = new Property();

    /**
     * 矿山-宝库宝箱数量
     */
    private int lotteryBoxNum;



    public List<KuangRankRewardConfig> getPersonRankRewardConfig(int openDay) {
        List<KuangRankRewardConfig> list = new ArrayList<>();
        if (personRankRewardConfigMap.containsKey(openDay)) {
            list.addAll(personRankRewardConfigMap.get(openDay));
        } else {
            // 找最大满足的配置
            int maxDay = -1;
            for (Map.Entry<Integer, List<KuangRankRewardConfig>> entry : personRankRewardConfigMap.entrySet()) {
                Integer day = entry.getKey();
                if (openDay >= day && day >= maxDay) {
                    maxDay = day;
                    list.clear();
                    list.addAll(entry.getValue());
                }
            }
        }
        return list;
    }

    public Property getPersonRankReward(int openDay, int rank) {
        Property property = new Property();
        List<KuangRankRewardConfig> rankRewardConfigList = getPersonRankRewardConfig(openDay);
        for (KuangRankRewardConfig rankRewardConfig : rankRewardConfigList) {
            if (rank >= rankRewardConfig.getMinRank() && rank <= rankRewardConfig.getMaxRank()) {
                property = PropertyHelper.parseStringToProperty(rankRewardConfig.getReward());
            }
        }
        return property;
    }

    public List<KuangRankRewardConfig> getGroupRankRewardConfig(int openDay) {
        List<KuangRankRewardConfig> list = new ArrayList<>();
        if (groupRankRewardConfigMap.containsKey(openDay)) {
            list.addAll(groupRankRewardConfigMap.get(openDay));
        } else {
            // 找最大满足的配置
            int maxDay = -1;
            for (Map.Entry<Integer, List<KuangRankRewardConfig>> entry : groupRankRewardConfigMap.entrySet()) {
                Integer day = entry.getKey();
                if (openDay >= day && day >= maxDay) {
                    maxDay = day;
                    list = new ArrayList<>(entry.getValue());
                }
            }
        }
        return list;
    }

    public Property getGroupRankReward(int openDay, int rank) {
        Property property = new Property();
        List<KuangRankRewardConfig> rankRewardConfigList = getGroupRankRewardConfig(openDay);
        for (KuangRankRewardConfig rankRewardConfig : rankRewardConfigList) {
            if (rank >= rankRewardConfig.getMinRank() && rank <= rankRewardConfig.getMaxRank()) {
                property = PropertyHelper.parseStringToProperty(rankRewardConfig.getReward());
            }
        }
        return property;
    }

    public List<PropertyWeightItem> getLotteryGeneraReward(int openDay) {
        List<PropertyWeightItem> list = new ArrayList<>();
        if (lotteryGeneraRewardMap.containsKey(openDay)) {
            list = new ArrayList<>(lotteryGeneraRewardMap.get(openDay));
        }else {
            // 找最大满足的配置
            int maxDay = -1;
            for (Map.Entry<Integer, List<PropertyWeightItem>> entry : lotteryGeneraRewardMap.entrySet()) {
                Integer day = entry.getKey();
                if (openDay >= day && day >= maxDay) {
                    maxDay = day;
                    list = new ArrayList<>(entry.getValue());
                }
            }
        }
        return list;
    }

    public List<PropertyWeightItem> getLotterySpecialReward(int openDay) {
        List<PropertyWeightItem> list = new ArrayList<>();
        if (lotterySpecialRewardMap.containsKey(openDay)) {
            list = new ArrayList<>(lotterySpecialRewardMap.get(openDay));
        }else {
            // 找最大满足的配置
            int maxDay = -1;
            for (Map.Entry<Integer, List<PropertyWeightItem>> entry : lotterySpecialRewardMap.entrySet()) {
                Integer day = entry.getKey();
                if (openDay >= day && day >= maxDay) {
                    maxDay = day;
                    list = new ArrayList<>(entry.getValue());
                }
            }
        }
        return list;
    }

    public Map<Integer, List<KuangRankRewardConfig>> getPersonRankRewardConfigMap() {
        return personRankRewardConfigMap;
    }

    public void setPersonRankRewardConfigMap(Map<Integer, List<KuangRankRewardConfig>> personRankRewardConfigMap) {
        this.personRankRewardConfigMap = personRankRewardConfigMap;
    }

    public Map<Integer, List<KuangRankRewardConfig>> getGroupRankRewardConfigMap() {
        return groupRankRewardConfigMap;
    }

    public void setGroupRankRewardConfigMap(Map<Integer, List<KuangRankRewardConfig>> groupRankRewardConfigMap) {
        this.groupRankRewardConfigMap = groupRankRewardConfigMap;
    }

    public Map<Integer, List<PropertyWeightItem>> getLotteryGeneraRewardMap() {
        return lotteryGeneraRewardMap;
    }

    public void setLotteryGeneraRewardMap(Map<Integer, List<PropertyWeightItem>> lotteryGeneraRewardMap) {
        this.lotteryGeneraRewardMap = lotteryGeneraRewardMap;
    }

    public Map<Integer, List<PropertyWeightItem>> getLotterySpecialRewardMap() {
        return lotterySpecialRewardMap;
    }

    public void setLotterySpecialRewardMap(Map<Integer, List<PropertyWeightItem>> lotterySpecialRewardMap) {
        this.lotterySpecialRewardMap = lotterySpecialRewardMap;
    }

    public Property getLotteryCost() {
        return lotteryCost;
    }

    public void setLotteryCost(Property lotteryCost) {
        this.lotteryCost = lotteryCost;
    }

    public int getLotteryBoxNum() {
        return lotteryBoxNum;
    }

    public void setLotteryBoxNum(int lotteryBoxNum) {
        this.lotteryBoxNum = lotteryBoxNum;
    }


}
